home *** CD-ROM | disk | FTP | other *** search
- Path: news.compuserve.com!newsmaster
- From: JamesCurran@CIS.CompuServe.Com (James M. Curran)
- Newsgroups: comp.lang.c
- Subject: Re: ugly constants and header files
- Date: Mon, 08 Jan 1996 04:26:13 GMT
- Organization: CompuServe Incorporated
- Message-ID: <4cq6d8$t51@dub-news-svc-1.compuserve.com>
- References: <1996Jan3.155754.111142@kuhub.cc.ukans.edu>
- NNTP-Posting-Host: ad08-014.compuserve.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- In <1996Jan3.155754.111142@kuhub.cc.ukans.edu>, anh@kuhub.cc.ukans.edu
- wrote:
-
- >>Is this the best solution? Are there any other way?
-
- To expand a bit on David Wright's method, in the common header file,
- use:
-
- #if defined(GLOBAL)
- #define PUBLIC
- #define VALUE(n) = n
- #else
- #define PUBLIC extern
- #define VALUE
- #endif
-
-
- then declare your variable in the following form:
-
- PUBLIC int nCount VALUE(5);
- PUBLIC char *sName VALUE("Hello, World!");
-
- then, again, #define GLOBAL at the top of only one module. When
- this module is compiled, the code will be rendered as:
-
- int nCount = 5;
- char *sName = "Hello, World!"l
-
- However, for the other file, it will be translated as:
-
- extern int nCount;
- extern char *sName;
-
- NOTE -- This method works for works fine for scalars, but chokes on
- array declarions. You'll have to fall back to David's method from
- them.
-
-
-
-
-
-
-
-